<?php

declare(strict_types=1);

namespace App\CustHub\Controller;

use App\CustHub\Annotation\ApiAuth;
use App\CustHub\Annotation\VerifySignature;
use App\CustHub\Request\RoomBroadcastSourceRequest;
use App\CustHub\Service\RoomBroadcastSourceService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\PostMapping;

/**
 * 群转播数据源
 */
#[Controller(prefix: 'ch/room/broadcast/source'),ApiAuth,VerifySignature]
class RoomBroadcastSourceController extends BaseController
{
    #[Inject]
    protected RoomBroadcastSourceService $service;

    #[PostMapping('list')]
    public function list()
    {
        $data = $this->request->all();
        $data['select'] = 'id,name,avatar,business_info';
        $data['pageSize'] = $data['page_size'] ?? 10;
        return $this->success($this->service->getPageList($data));
    }

    /**
     * 新增数据源
     * @param RoomBroadcastSourceRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('save')]
    public function save(RoomBroadcastSourceRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->service->saveSource($request->all()) ? $this->success() : $this->error();
    }

    /**
     * 详情
     * @param RoomBroadcastSourceRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('detail')]
    public function detail(RoomBroadcastSourceRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->success($this->service->detail($request->all()));
    }

    /**
     * 修改数据源
     * @param RoomBroadcastSourceRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('update')]
    public function update(RoomBroadcastSourceRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->service->updateSource($request->all()) ? $this->success() : $this->error();
    }

    /**
     * 删除数据源
     * @param RoomBroadcastSourceRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('delete')]
    public function delete(RoomBroadcastSourceRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->service->deleteSource($request->all()) ? $this->success() : $this->error();
    }
}